<template>
  <div id="index" class="bigscreen">
    <dv-full-screen-container class="bg">
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else class="host-body">
        <div class="d-flex jc-center">
          <dv-decoration-10 style="width:30%;height:.0625rem;" />
          <div class="d-flex jc-center flex1">
            <dv-decoration-8 :color="['#568aea', '#000000']" style="width:22%;height:0.8rem;" />
            <div class="title">
              <span class="title-text">{{ $t('ELM-C5-vtFllsbMY0tfKE') }}</span>
              <dv-decoration-6
                class="title-bototm"
                :reverse="true"
                :color="['#50e3c2', '#67a1e5']"
                style="width:49%;height:.1rem;"
              />
            </div>
            <dv-decoration-8
              :reverse="true"
              :color="['#568aea', '#000000']"
              style="width:22%;height:0.8rem;"
            />
          </div>
          <dv-decoration-10 style="width:30%;height:.0625rem; transform: rotateY(180deg);" />
        </div>

        <!-- 第二行 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex" style="width: 40%">
            <div
              class="react-right ml-4"
              style="width: 69%; height: 0.8rem; text-align: left;background-color: #0f1325;"
            >
              <span class="react-before" style="height: 0.8rem;"></span>
              <span class="text"></span>
            </div>
            <div class="react-right bg-color-blue ml-3" style="width: 31%; height: 0.8rem; background-color: #0f1325;">
              <span class="text colorBlue"></span>
            </div>
          </div>
          <div style="width: 40%" class="d-flex">
            <div class="react-left bg-color-blue mr-3" style="width: 31%; height: 0.8rem; background-color: #0f1325;">
              <span class="text fw-b"></span>
            </div>
            <div
              class="react-left mr-4"
              style="width: 69%; height: 0.8rem; background-color: #0f1325; text-align: right;"
            >
              <span class="react-after" style="height: 0.8rem;"></span>
              <span class="text">{{ time }}</span>
            </div>
          </div>
        </div>

        <div class="body-box">
          <!-- 第三行数据 -->
          <div class="content-box">
            <div>
              <dv-border-box-12 :key="boxKey1" style="height:6rem;">
                <centerLeft2/>
              </dv-border-box-12>
            </div>
            <!-- 中间 -->
            <div>
              <dv-border-box-12 :key="boxKey2" style="height:6rem;">
                <center />
              </dv-border-box-12>
            </div>
            <!-- 中间 -->
            <!-- <div>
              <centerRight2 />
            </div> -->
            <div>
              <dv-border-box-13 :key="boxKey3" style="height:6rem;">
                <centerRight1 />
              </dv-border-box-13>
            </div>
          </div>

          <!-- 第四行数据 -->
          <div class="bototm-box">
            <dv-border-box-13 :key="boxKey4" style="height:7rem;">
              <bottomLeft />
            </dv-border-box-13>
            <dv-border-box-12 :key="boxKey5" style="height:7rem;">
              <bottomRight />
            </dv-border-box-12>
          </div>
        </div>
      </div>
    </dv-full-screen-container>
  </div>
</template>

<script>
import centerLeft2 from './centerLeft2'
import centerRight1 from './centerRight1'
// import centerRight2 from './centerRight2'
import center from './center'
import bottomLeft from './bottomLeft'
import bottomRight from './bottomRight'
import moment from 'moment'
import { bigscreen } from '@/api/data2'
import { createNamespacedHelpers } from 'vuex'
import renderMixin from '@/mixins/render'

import '@/assets/scss/index.scss'
const { mapMutations } = createNamespacedHelpers('screen')

export default {
  mixins: [ renderMixin ],
  props: {
    id: String
  },
  data () {
    return {
      loading: true,
      time: moment().format('YYYY-MM-DD HH:mm:ss'),
      timer: null,
      timer2: null,
      key: Date.now() + ''
      // data: {}
    }
  },
  computed: {
    boxKey1 () {
      return this.key + 'key1'
    },
    boxKey2 () {
      return this.key + 'key2'
    },
    boxKey3 () {
      return this.key + 'key3'
    },
    boxKey4 () {
      return this.key + 'key4'
    },
    boxKey5 () {
      return this.key + 'key5'
    }
  },
  components: {
    centerLeft2,
    centerRight1,
    center,
    bottomLeft,
    bottomRight
  },
  async mounted () {
    this.updateTime()
    await this.queryData()
    this.loading = false
    this.renderInterval()
  },
  methods: {
    ...mapMutations(['setScreenData']),
    renderInterval () {
      // 3分钟
      this.timer2 = setInterval(() => {
        this.queryData()
      }, this.$config.screenIntervalTime * 1000)
    },
    async queryData () {
      const { code, data = {}, desc } = await bigscreen({
        stationid: +this.id
      })
      if (code == 200) {
        if (data.todaydata && data.totaldata) {
          _.assign(data, {
            detail: {
              today_elec: data.todaydata.elec,
              today_count: data.todaydata.count,
              today_amount: data.todaydata.amount,
              total_elec: data.totaldata.elec,
              total_count: data.totaldata.count,
              total_amount: data.totaldata.amount
            }
          })
        }
        // this.data = data
        this.setScreenData(data)
      } else {
        this.$Message.error(desc)
      }
    },
    updateTime () {
      this.timer = setInterval(() => {
        this.time = moment().format('YYYY-MM-DD HH:mm:ss')
      }, 1000)
    }
  },
  beforeDestroy () {
    this.timer && clearInterval(this.timer)
    this.timer2 && clearInterval(this.timer2)
  }
}
</script>

<style lang="stylus" scoped>
.flex1
  flex 1
</style>
